import request from '@/utils/request-student'


/**
 * 获取学科列表
 * @param null 全查 
 * @returns {Promise}
 */
export function getSubjectsAndStatus() {
    return request({
        url: '/student/exam/subject-status',
        method: 'get'
    })
}



/**
 * 获取考试列表
 * @param {Object} params 查询参数， subjectId,examStatusId，
 * @returns {Promise}
 */
export function getExamList(params) {
    return request({
        url: '/student/exam/list',
        method: 'get',
        params
    })
}

/**
 * 获取考试详情
 * @param {Number} examId 考试ID
 * @returns {Promise}
 */
export function getExamDetail(examId) {
    return request({
        url: `/student/exam/detail/${examId}`,
        method: 'get'
    })
}

export function getExamDetailSimple(examId) {
    return request({
        url: `/student/exam/detailSimple/${examId}`,
        method: 'get'
    })
}

/**
 * 获取考试规则
 * @param {Number} examId 考试ID
 * @returns {Promise}
 */
export function getExamRules(examId) {
    return request({
        url: `/student/exam/rules/${examId}`,
        method: 'get'
    })
}

/**
 * 获取考试进度
 * @param {Number} studentPaperId 试卷ID
 * @returns {Promise}
 */
export function getExamProgress(studentPaperId) {
    return request({
        url: `/student/exam/progress/${studentPaperId}`,
        method: 'get'
    })
}

/**
 * 保存单个答案
 * @param {Number} examId 考试ID
 * @param {Object} data 答案数据，包含 paperDetailId、questionId、answer、timeSpent
 * @returns {Promise}
 */
export function saveAnswerToServer(examId, data) {
    return request({
        url: `/student/exam/save-answer/${examId}`,
        method: 'post',
        data
    })
}

/**
 * 批量保存答案
 * @param {Number} examId 考试ID
 * @param {Object} data 批量答案数据，answers数组中每项包含 paperDetailId、questionId、answer、timeSpent
 * @returns {Promise}
 */
export function saveBatchAnswers(examId, data) {
    return request({
        url: `/student/exam/save-batch-answers/${examId}`,
        method: 'post',
        data
    })
}

/**
 * 记录违规行为
 * @param {Number} examId 考试ID
 * @param {Object} data 违规记录数据
 * @returns {Promise}
 */
export function recordViolation(examId, data) {
    return request({
        url: `/student/exam/record-violation/${examId}`,
        method: 'post',
        data
    })
}

/**
 * 提交试卷
 * @param {Number} examId 考试ID
 * @param {Object} data 试卷数据(这里只有studentPaperId)
 * @returns {Promise}
 */
export function submitExam(examId, data) {
    return request({
        url: `/student/exam/submit/${examId}`,
        method: 'post',
        data
    })
}

/**
 * 获取成绩列表
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function getScoreList(params) {
    return request({
        url: '/student/score/list',
        method: 'get',
        params
    })
}

/**
 * 获取成绩详情
 * @param {Number} examId 考试ID
 * @returns {Promise}
 */
export function getScoreDetail(examId) {
    return request({
        url: `/student/score/detail/${examId}`,
        method: 'get'
    })
}

/**
 * 申请换机
 * @param {Object} data 换机申请数据
 * @returns {Promise}
 */
export function applyChangeMachine(data) {
    return request({
        url: '/student/change-machine/apply',
        method: 'post',
        data
    })
}

/**
 * 获取换机申请历史
 * @returns {Promise}
 */
export function getChangeMachineHistory() {
    return request({
        url: '/student/change-machine/history',
        method: 'get'
    })
}


